package utils;

import bean.Clothes;

import java.util.ArrayList;
import java.util.List;

public class ClothesIO {

    //商品列表
    private List<Clothes> clothesList = new ArrayList<>();

    //根据商品的id查询商品
    public Clothes findById(String cid) throws BusinessException {
        for (Clothes clothes : clothesList) {
            if (clothes.getId().equals(cid)) {
                return clothes;
            }
        }
        return null;
    }

    //查询商品列表
    public List<Clothes> list() throws BusinessException {
        if (clothesList.size() == 0) {
            clothesList = ProductsXMLUtils.parseProductFormXML();
        }
        return clothesList;
    }

    //更新XML文件
    public void update() throws BusinessException{
        ProductsXMLUtils.writeProductToXML(list());
    }
}
